package com.cvit.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cvit.dao.RolePermissionMapper;
import com.cvit.model.RolePermissionKey;

@Service
public class RolePermissionService {

	/**
	 * @author WYHY
	 * */
	@Autowired
	RolePermissionMapper rolePermissionMapper;
	
	/**
	 * @param 给角色添加/修改权限
	 * @author WYHY
	 * */
	public int permissionToRole(String roleid,List permissionid) {
		int a=0;
		RolePermissionKey rolePermissionKey=new RolePermissionKey();
		rolePermissionKey.setRoleid(Integer.parseInt(roleid));
		rolePermissionMapper.deleteByPrimaryKey(rolePermissionKey);
		for (int i = 0; i < permissionid.size(); i++) {
			String r=String.valueOf(permissionid.get(i));
			RolePermissionKey rolePermissionKey1=new RolePermissionKey();
			rolePermissionKey1.setRoleid(Integer.parseInt(roleid));
			rolePermissionKey1.setPermissionid(Integer.parseInt(r));
			rolePermissionMapper.insert(rolePermissionKey1);
			a++;
		}
		return a;
	}
	
	/**
	 * @param 角色查询权限
	 * @author WYHY
	 * */
	public List roleSelPermission(String roleid) {
		List list=rolePermissionMapper.selectByRoleid(Integer.parseInt(roleid));
		return list;
	}
}
